package com.ihr360.shared.basicstaffinfo.convertor;

import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.entity.BasicStaffInfoEntity;
import com.ihr360.shared.basicstaffinfo.dto.SyncedBasicStaffInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Stone.Shi
 * @description
 * @date 2018-03-07 10:56:18.
 */
@Component
public class SyncedBasicStaffInfoConvertor implements IConvertor<BasicStaffInfoEntity, SyncedBasicStaffInfo> {

    @Override
    public SyncedBasicStaffInfo convertEntityToDto(BasicStaffInfoEntity entity) {
        return null;
    }

    @Override
    public BasicStaffInfoEntity convertDtoToEntity(SyncedBasicStaffInfo dto) {
        if (dto == null) {
            return null;
        }
        BasicStaffInfoEntity entity = new BasicStaffInfoEntity();
        BeanUtils.copyProperties(dto, entity);
        return entity;
    }

    public List<BasicStaffInfoEntity> convertDtosToEntities(List<SyncedBasicStaffInfo> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Collections.emptyList();
        }
        List<BasicStaffInfoEntity> entities = new ArrayList<>(dtos.size());
        dtos.forEach(dto -> entities.add(convertDtoToEntity(dto)));
        return entities;
    }
}
